#include "NSector.h"
#include "NMemoryManager.h"
#include "NObject.h"
using namespace Core;

RTTI_DEFINITIONS(NSector)

NSector::NSector(void)
	:NAttributed()
{
}


NSector::~NSector(void)
{
	unsigned int size = mMembers.size();
	for(int i = size-1; i >= 0; i--)
	{
		NDatum & aDatum = this->operator[](i);
		if(aDatum.GetType() == NDatum::eTYPE_SCOPE)
		{
			for(unsigned int j = 0; j < aDatum.GetNumValues();j++)
			{
				if(aDatum.Get<NScope*>(j)->Is("NEntity"))
				{
					NObject* comp = reinterpret_cast<NObject*>(aDatum.Get<NScope*>(j));
					MY_DELETE( comp );
				}
			}
		}
	}
}

void NSector::Initialize()
{
	for(unsigned int i = 0; i < Size() ; i++)
	{
		NDatum & aDatum = this->operator[](i);
		if(aDatum.GetType() == NDatum::eTYPE_SCOPE)
		{
			for(unsigned int j = 0; j < aDatum.GetNumValues();j++)
			{
				if(aDatum.Get<NScope*>(j)->Is("NEntity"))
				{
					//reinterpret_cast<NObject*>(aDatum.Get<NScope*>(j))->Initialize();
				}
			}
		}
	}
}

void NSector::Deinitialize()
{
	
}


void NSector::Update(float deltaTime)
{
	for(unsigned int i = 0; i < Size() ; i++)
	{
		NDatum & aDatum = this->operator[](i);
		if(aDatum.GetType() == NDatum::eTYPE_SCOPE)
		{
			for(unsigned int j = 0; j < aDatum.GetNumValues();j++)
			{
				if(aDatum.Get<NScope*>(j)->Is("NEntity"))
				{
					reinterpret_cast<NObject*>(aDatum.Get<NScope*>(j))->Update(deltaTime);
				}
			}
		}
	}
}

void NSector::Render(float)
{
	for(unsigned int i = 0; i < Size() ; i++)
	{
		NDatum & aDatum = this->operator[](i);
		if(aDatum.GetType() == NDatum::eTYPE_SCOPE)
		{
			for(unsigned int j = 0; j < aDatum.GetNumValues();j++)
			{
				if(aDatum.Get<NScope*>(j)->Is("NEntity"))
				{
					//reinterpret_cast<NObject>(aDatum.Get<NScope*>(j))->Render(deltaTime);
				}
			}
		}
	}
}

int NSector::Serialize(Core::NArchive ar)
{
	int status = Core::NArchive::STATUS_SUCCESS;

	return status;
}

int NSector::Deserialize(Core::NArchive ar)
{
	int status = Core::NArchive::STATUS_SUCCESS;

	return status;
}
